package com.example.mytayunapi.Service;

import com.example.mytayunapi.Entity.userInfo;
import com.example.mytayunapi.Mapper.userInfoMapper;
import com.example.mytayunapi.Vo.UserProduct;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


import java.util.List;

@Service

public class userInfoServiceImpl implements userInfoService{
    @Autowired
    private userInfoMapper userinfoMapper;


    @Override
    public List<userInfo> getNickname(String School_degree) {
        return userinfoMapper.getNickname(School_degree);
    }

    @Override
    public List<userInfo> getUserInfo() {
        return userinfoMapper.getUserInfo();
    }

    @Override
    public PageInfo<userInfo> getPageInfo(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<userInfo> userInfo = userinfoMapper.getUserInfo();
        PageInfo<userInfo> pageInfo = new PageInfo<>(userInfo);
        return pageInfo;
    }

    @Override
    public List<userInfo> getSchool_degree(String School_degree) {
        return userinfoMapper.getSchool_degree(School_degree);
    }

    @Override
    public Integer updateUserInfo(userInfo userinfo) {
        return userinfoMapper.updateUserInfo(userinfo);
    }

    @Override
    public Integer insertUserInfo(userInfo userinfo) {
        return userinfoMapper.insertUserInfo(userinfo);
    }

    @Override
    public userInfo getUserdegreeApass(String School_degree, String password) {
        // 从数据库获取userInfo对象
        userInfo user = userinfoMapper.getUserdegreeApass(School_degree, password);

        // 检查用户是否存在
        if (user != null) {
            // 清理School_degree字段，确保不包含URL安全的Base64非法字符
            String cleanedSchoolDegree = School_degree.replaceAll("[+/=]", "_");
            user.setSchool_degree(cleanedSchoolDegree); // 假设setSchool_degree是userInfo类的一个setter方法
        }

        // 返回处理后的用户信息
        return user;
    }

    @Override
    public List<userInfo> getUserdegree(String School_degree) {
        return userinfoMapper.getUserdegree(School_degree);
    }

    @Override
    public Integer changeUserInfo(userInfo userinfo) {
        return userinfoMapper.changeUserInfo(userinfo);
    }

    @Override
    public Integer changeUserInfoLogin(userInfo userinfo) {
        return userinfoMapper.changeUserInfoLogin(userinfo);
    }

    @Override
    public Integer changeUserInfoPassword(userInfo userinfo) {
        return userinfoMapper.changeUserInfoPassword(userinfo);
    }

    @Override
    public String getSchool_number(String School_degree) {
        return userinfoMapper.getSchool_number(School_degree);
    }

    @Override
    public String getSchool_name(String School_degree) {
        return userinfoMapper.getSchool_name(School_degree);
    }

    @Override
    public Integer updateUserInfoName(userInfo userinfo) {
        return userinfoMapper.updateUserInfoName(userinfo);
    }

    @Override
    public List<UserProduct> getmaijiaxuehao(Integer Product_id) {
        return userinfoMapper.getmaijiaxuehao(Product_id);
    }

    @Override
    public Integer updateUsersInfoName(userInfo userinfo) {
        Integer i = userinfoMapper.updateUsersInfoName(userinfo);
        return i;
    }

    @Override
    public Integer updateUsersQXInfoName(userInfo userinfo) {
        Integer i= userinfoMapper.updateUsersQXInfoName(userinfo);
        return i;
    }

    @Override
    public List<userInfo> getyonghu(String School_degree) {
        return userinfoMapper.getyonghu(School_degree);
    }

}

